﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;
using UFIDA.U9.SM.Ship;
using UFIDA.U9.PM.PO;
using UFSoft.UBF.PL;
using UFIDA.U9.PM.Rcv;
using UFIDA.U9.SM.RMA;
using UFIDA.U9.SM.SO;
using UFIDA.U9.CBO.SCM.Customer;
using UFIDA.U9.PR.PurchaseRequest;
using UFSoft.UBF.Util.DataAccess;
using UFSoft.UBF.PL.Engine;
using System.Security.Cryptography;


namespace UFIDA.U9.Cust.LS.PlugBE
{
    /// <summary>
    /// 爱发科
    /// 采购订单
    /// 审核时更新料品9
    /// 新增 初始版本
    /// 提交时,版本+1
    /// </summary>
    class AFKPOToPRExtend : IEventSubscriber
    {
        //配置XX.sub.xml文件放置到portal/bin下，dll文件放置到portal/ApplicationServer/Libs下
        public void Notify(params object[] args)
        {
            if (args != null && args.Length != 0 && args[0] is EntityEvent)
            {
                BusinessEntity.EntityKey key = ((EntityEvent)args[0]).EntityKey;
                UFIDA.U9.PM.PO.PurchaseOrder be = key.GetEntity() as UFIDA.U9.PM.PO.PurchaseOrder;
                if (be == null)
                    return;
                if (be.Org.Code.Contains("UCD") || be.Org.Code.Contains("UCDH"))
                {

                    if ((be.Status == PODOCStatusEnum.Approved && be.OriginalData.Status == PODOCStatusEnum.Approving))

                    {

                        //保存时 更新料品对应单价
                        foreach (var line in be.POLines)
                        {
                            Decimal FinallyPriceTC = line.FinallyPriceTC;
                            String sql = "Update CBO_ItemMaster set DescFlexField_PrivateDescSeg9='" + be.FC.Symbol + " " + line.FinallyPriceTC.ToString() + " '  WHERE id='" + line.ItemInfo.ItemID.ID + "'and org='" + be.Org.ID + "'";
                            DataAccessor.RunSQL(DataAccessor.GetConn(), sql, null);
                        }
                    }
                }
                 
                }
            }
        }
     
}
